<template>
	<view class="p_bg_all p_b_128">
		<noneData noneTitle="暂无数据~" v-if="listData.length === 0"></noneData>
		<view class="list_wrapper" v-for="item in listData" :key="item.id">
			<image src="https://dy.sykj365.com/uploads/mini/weixuanzhong@2x.png" class="p_img_48 p_margin_r_32" v-if="!item.choose"
				@click="item.choose = true">
			</image>
			<image src="https://dy.sykj365.com/uploads/mini/xuanzhong@2x.png" class="p_img_48 p_margin_r_32" v-if="item.choose"
				@click="item.choose = false"></image>
			<view class="p_flex_1 p_flex">
				<image src="https://dy.sykj365.com/uploads/mini/file@2x.png" mode="aspectFill" class="p_img_64 p_margin_r_16">
				</image>
				<view class="p_flex_1">
					<view class="p_flex">
						<view class="p_font_32 p_flex_1">{{item.name}}</view>
					</view>
					<view class="p_font_28 p_color_b2 p_margin_t_8">文件数量<text
							class="p_color_7a p_margin_l_16">{{item.file_num}}个</text>
					</view>
					<view class="p_font_28 p_color_b2 p_margin_t_8">订单编号<text
							class="p_color_7a p_margin_l_16">{{item.order_num}}</text></view>
					<view class="p_font_28 p_color_b2 p_margin_t_8">下单时间<text
							class="p_color_7a p_margin_l_16">{{item.create_time}}</text></view>
					<view class="p_font_28 p_color_b2 p_margin_t_8">订单金额<text
							class="p_color_ff5555 p_margin_l_16">{{item.order_price}}元</text></view>
				</view>
			</view>
		</view>
		<bottomView btnText1="确定" btnText2="取消" @getSubmit="getSubmit" @getClear="getClear" v-if="listData.length > 0">
		</bottomView>
	</view>
</template>

<script>
	import noneData from '../../components/noneData.vue';
	import bottomView from '../../components/bottomView.vue';

	export default {
		components: {
			noneData,
			bottomView
		},
		data() {
			return {
				ids: [],
				listData: [],
			}
		},
		onLoad(e) {
			if(e.ids) {
				this.ids = e.ids.split(',')
			}
			this.getListData();
		},
		methods: {
			getListData() {
				this.$http.post(this.$api.invoiceList).then(res => {
					if (res.data.length > 0) {
						res.data.forEach((n) => {
							n.choose = false;
							if(this.ids.length > 0) {
								this.ids.forEach((m) => {
									if(n.id == m) {
										n.choose = true;
									}
								})
							}
						})
					}
					this.listData = res.data;
				})
			},
			getSubmit() {
				let arr = [];

				this.listData.forEach((n) => {
					if (n.choose) {
						arr.push({
							id: n.id,
							name: n.name,
							order_price: n.order_price
						})
					}
				})

				if (arr.length === 0) return getApp().getMsg('请选择订单');
				uni.navigateBack();
				uni.setStorageSync('invoiceOrder', JSON.stringify(arr));
			},
			getClear() {
				uni.navigateBack();
			}
		}
	}
</script>

<style lang="less">
	.list_wrapper {
		padding: 32rpx;
		margin: 32rpx;
		border-radius: 16rpx;
		background-color: #fff;
		display: flex;
		align-items: center;
	}
</style>